home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / libscsi1.zoo / LibScsi-0.01 / scsi.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-14  |  15.8 KB  |  378 lines

  1. /*
  2.  * <sys/scsi.h> - Steve Woodford, August 1993
  3.  *
  4.  * Declare data structures passed to and from Scsi Targets.
  5.  * Include this if you want to use the low-level device interface.
  6.  * The high level 'scsi_io' interface is preferable, however.
  7.  */
  8.  
  9. #ifndef __sys_scsi_h
  10. #define __sys_scsi_h
  11.  
  12. #define MAX_SCSI_ID             7       /* Targets 0 -> 7 allowed */
  13. #define MAX_LUN_ID              7       /* Logical units per target */
  14.  
  15. /*
  16.  * Completion codes returned from all Scsi driver functions.
  17.  */
  18. #define CBYTE_OK                0x00    /* No errors during command   */
  19. #define CBYTE_CHECK_CONDITION   0x02    /* Target detected error      */
  20. #define CBYTE_BUSY              0x04    /* Target is Busy             */
  21. #define CBYTE_TIMEOUT           (-1)    /* Timeout initiating command */
  22.  
  23.  
  24. /*
  25.  * Response to 'Inquire' command
  26.  */
  27. typedef struct {
  28.     u_char      iq_type;            /* Peripheral device type */
  29. #define DTYPE_RANDOM        0x00    /* Random access device */
  30. #define DTYPE_SEQUENTIAL    0x01    /* Sequential access device */
  31.     /*
  32.      * There are more device types, but my SCSI spec. is not
  33.      * up to date enough, plus the fact that I don't own any other
  34.      * type, so I can't test the code!
  35.      */
  36.  
  37.     unsigned    iq_remove   :1;     /* Set indicates removable media */
  38.     unsigned    iq_qual     :7;     /* Device type qualifier */
  39.     u_char      iq_version;         /* ECMA / ANSI version compliance */
  40.     unsigned    iq_resvd    :4;
  41.     unsigned    iq_rdformat :4;     /* Response data format */
  42.     u_char      iq_length;          /* Additional length */
  43.     u_char      iq_vu[3];           /* Vendor unique padding */
  44.     char        iq_vendor[8];       /* Vendor Name */
  45.     char        iq_product[16];     /* Product Name */
  46.     char        iq_revision[4];     /* Revision level */
  47. } Sc_Inquire;
  48.  
  49.  
  50. /*
  51.  * Standard (Non-Extended) Scsi Sense data
  52.  */
  53. typedef struct {
  54.     unsigned      ss_valid  :1;     /* Sense Address valid */
  55.     unsigned      ss_class  :3;     /* Error Class (See Below) */
  56.     unsigned      ss_code   :4;     /* Error Code (See Below) */
  57.     unsigned long ss_addr   :24;    /* Address pertaining to error */
  58. } Sc_Sense;
  59.  
  60. /*
  61.  * Extended Scsi Sense data
  62.  */
  63. typedef struct {
  64.     unsigned    ss_valid    :1;     /* Data valid */
  65.     unsigned    ss_class    :3;     /* Error Class (See Below) */
  66.     unsigned    ss_code     :4;     /* Error Code (See Below) */
  67.     u_char      ss_segment;         /* Segment number (Copy command only) */
  68.                                     /* Note: Copy cannot be implemented on */
  69.                                     /* the ACSI bus, so this is redundant. */
  70.     unsigned    ss_fm       :1;     /* File mark detected */
  71.     unsigned    ss_eom      :1;     /* End of Media detected */
  72.     unsigned    ss_ili      :1;     /* Incorrect length indicator */
  73.     unsigned                :1;     /* Reserved */
  74.     unsigned    ss_sensekey :4;     /* Sense Key (See below) */
  75.     u_char      ss_info1;           /* 4 information bytes */
  76.     u_char      ss_info2;
  77.     u_char      ss_info3;
  78.     u_char      ss_info4;
  79.     u_char      ss_add_len;         /* Number of additional bytes */
  80.     u_char      ss_info5;           /* Used for search & copy only */
  81.     u_char      ss_info6;
  82.     u_char      ss_info7;
  83.     u_char      ss_info8;
  84.     u_char      ss_sensecode;       /* Additional sense code */
  85.     u_char      ss_info9;           /* Reserved/Error count */
  86.     u_char      ss_additional[3];   /* Pad to 16 bytes */
  87. } Sc_X_Sense;
  88.  
  89. /* For Archive Viper tape drive, residual transfer length */
  90. #define residue_length(z)   ((long)( ((z).ss_info1 << 24) | \
  91.                                      ((z).ss_info2 << 16) | \
  92.                                      ((z).ss_info3 <<  8) | \
  93.                                       (z).ss_info4))
  94.  
  95. #define soft_errors(z)      ((short)(((z).ss_sensecode << 8) | \
  96.                                      ((z).ss_info9)))
  97.  
  98.  
  99. /*
  100.  * Response to Mode Sense command
  101.  */
  102. typedef struct {
  103.     u_char      ms_length;          /* Additional length (should be 8) */
  104.     u_char      ms_media_type;      /* Media Type */
  105.     unsigned    ms_write_prot :1;   /* Write protected flag */
  106.     unsigned    ms_info       :7;
  107.     u_char      ms_bdesc_len;       /* Block descriptor length (bytes) */
  108.     struct _Sc_Block_Descriptor {
  109.         u_char   ms_density;        /* Density code (See below) */
  110.         unsigned long ms_blocks :24;/* Number of blocks on media */
  111.         u_char   ms_reserved;
  112.         unsigned long ms_blk_len:24;/* Length of a block */
  113.     } ms_bd;
  114. } Sc_Mode_Sense;
  115. /*
  116.  * Easy access for Archive Viper Tapedrive values.
  117.  */
  118. #define ms_density              ms_bd.ms_density
  119. #define ms_blocks               ms_bd.ms_blocks
  120. #define ms_blk_len              ms_bd.ms_blk_len;
  121. #define ms_buffer_mode(z)       (((z).ms_info >> 4) & 0x07)
  122. #define ms_speed(z)             ((z).ms_info & 0x0f)
  123.  
  124. /*
  125.  * For Archive Viper, the following define the Density codes
  126.  */
  127. #define DENSITY_VIPER_150       0x10    /* 150 Megabyte (18 tracks) */
  128. #define DENSITY_VIPER_120       0x0f    /* 120 Megabyte (15 tracks) */
  129. #define DENSITY_VIPER_60        0x05    /*  60 Megabyte ( 9 tracks) */
  130. #define DENSITY_VIPER_AUTO      0x00    /* Auto Sensing (2150 only) */
  131.  
  132.  
  133. /*
  134.  * Enumeration for READ/WRITE for Scsi_RdWr_???() functions.
  135.  * These MUST be used when accessing the functions.
  136.  */
  137. typedef enum {
  138.     SCSI_READ = 0,
  139.     SCSI_WRITE = 1
  140. } Sc_RW;
  141.  
  142.  
  143. /*
  144.  * This is the timeout structure type...
  145.  */
  146. typedef struct {
  147.     short   st_normal;      /* Commands that don't imply mechanical movement */
  148.     short   st_rezero;      /* Rezero Target (Or Rewind, for tapes)          */
  149.     short   st_read;        /* Read Data, with implied seek                  */
  150.     short   st_write;       /* Write Data, with implied seek                 */
  151.     short   st_seek;        /* Seek to a particular block                    */
  152.     short   st_load;        /* For Tape Drives, Tape load time               */
  153.     short   st_unload;      /* For Tape Drives, Tape unload time             */
  154.     short   st_retension;   /* Time to retension tape in tape drive          */
  155.     short   st_space;       /* Time to skip a tape file mark                 */
  156.     short   st_erase;       /* Time to erase entire tape                     */
  157. } Sc_Timeout;
  158.  
  159.  
  160. #ifndef SK_NO_SENSE
  161. /*
  162.  * Scsi Sense key values (ss_sensekey in above structure)
  163.  */
  164. #define SK_NO_SENSE             0x00
  165. #define SK_RECOVERABLE_ERROR    0x01    /* Recoverable error occurred */
  166. #define SK_NOT_READY            0x02    /* Drive Not Ready error */
  167. #define SK_MEDIA_ERROR          0x03    /* Medium Error */
  168. #define SK_HARDWARE_ERROR       0x04    /* Hardware error */
  169. #define SK_ILLEGAL_REQUEST      0x05    /* Illegal Request error */
  170. #define SK_UNIT_ATTENTION       0x06    /* Unit Attention Error */
  171. #define SK_DATA_PROTECTED       0x07    /* Usually Write Protect error */
  172. #define SK_BLANK_CHECK          0x08    /* Blank check error */
  173. #define SK_VENDOR_UNIQUE        0x09    /* Vendor Unique error */
  174. #define SK_COPY_ABORTED         0x0a    /* Copy aborted error */
  175. #define SK_ABORTED_COMMAND      0x0b    /* Aborted Command error */
  176. #define SK_EQUAL                0x0c    /* Equal error */
  177. #define SK_VOLUME_OVERFLOW      0x0d    /* Volume Overflow error */
  178. #define SK_MISCOMPARE           0x0e    /* Miscompare error */
  179. #define SK_RESERVED             0x0f
  180. /* The following sense keys are generated only by the Scsi_Io drivers */
  181. #define SK_TIMEOUT              0x10    /* Scsi Bus Timeout */
  182. #define SK_EOF                  0x11    /* Filemark */
  183. #define SK_EOT                  0x12    /* End of tape */
  184. #define SK_BOT                  0x13    /* Beginning of tape */
  185. #define SK_MEDIA                0x14    /* Wrong media */
  186. #define SK_BUSY                 0x15    /* Device busy */
  187.  
  188.  
  189. /*
  190.  * Additional Sense Codes (ss_sensecode) in above structure.
  191.  * Not every code is possible with every Sense key, and not all
  192.  * targets implement these. To be safe, stick with the normal
  193.  * Sense Keys.
  194.  */
  195. #define SC_NO_ERRR              0x00
  196. #define SC_NO_INDEX             0x01
  197. #define SC_NO_SEEK_COMPLETE     0x02
  198. #define SC_WRITE_FAULT          0x03
  199. #define SC_NOT_READY            0x04
  200. #define SC_DRIVE_NOT_SELECTED   0x05
  201. #define SC_TRACK_ZERO_ERROR     0x06
  202. #define SC_MULTIPLE_DRIVES      0x07
  203. #define SC_COMMS_FAILURE        0x08
  204. #define SC_TRACKING_ERROR       0x09
  205. /**/
  206. #define SC_BAD_CRC              0x10
  207. #define SC_UNRECOVERED_ERROR    0x11
  208. #define SC_ID_ADDR_MARK         0x12
  209. #define SC_DATA_ADDR_MARK       0x13
  210. #define SC_RECORD_NOT_FOUND     0x14
  211. #define SC_SEEK_ERROR           0x15
  212. #define SC_DATA_SYNC_ERROR      0x16
  213. #define SC_RETRY_READ_ERROR     0x17
  214. #define SC_ECC_READ_ERROR       0x18
  215. #define SC_DEFECT_LIST_ERROR    0x19
  216. #define SC_PARAMETER_OVERRUN    0x1a
  217. #define SC_SYNC_TRANSFER_ERROR  0x1b
  218. #define SC_DEFECT_LIST_LOST     0x1c
  219. #define SC_COMPARE_ERROR        0x1d
  220. #define SC_ECC_ID_ERROR         0x1e
  221. /**/
  222. #define SC_INVALID_CMD_CODE     0x20
  223. #define SC_INVALID_BLOCK_ADDR   0x21
  224. #define SC_INVALID_FUNCTION     0x22
  225. #define SC_VOLUME_OVERFLOW      0x23
  226. #define SC_INVALID_CDB          0x24
  227. #define SC_INVALID_LUN          0x25
  228. #define SC_INVALID_PARAM_LIST   0x26
  229. #define SC_WRITE_PROTECTED      0x27
  230. #define SC_MEDIA_CHANGED        0x28
  231. #define SC_DEVICE_RESET         0x29
  232. #define SC_MODE_SELECT_CHANGED  0x2a
  233. /**/
  234. #define SC_INCORRECT_MEDIA      0x30
  235. #define SC_FORMAT_FAILED        0x31
  236. #define SC_DEFECT_LIST_FULL     0x32
  237. /**/
  238. #define SC_RAM_FAILURE          0x40
  239. #define SC_ECC_FAILURE          0x41
  240. #define SC_POWER_ON_FAILURE     0x42
  241. #define SC_MESSAGE_REJECT_FAIL  0x43
  242. #define SC_SCSI_FAILURE         0x44
  243. #define SC_SELECT_TIMEOUT       0x45
  244. #define SC_SOFT_RESET_FAILED    0x46
  245. #define SC_SCSI_PARITY_ERROR    0x47
  246. #define SC_INITIATOR_ERROR      0x48
  247. #define SC_ILLEGAL_MESSAGE      0x49
  248. #define SC_UNABLE_TO_RESELECT   0x4a
  249. #define SC_NO_RECOVERY          0x4b
  250. /**/
  251. #define SC_ILLEGAL_BLOCK_DESC   0x50
  252. #define SC_INVALID_DATA_FIELD   0x51
  253. #define SC_BAD_DEFECT_LST_HDR   0x52
  254. /**/
  255. #define SC_DEVICE_RESET2        0x60
  256. #define SC_MODE_SELECT_CHANGED2 0x61
  257.  
  258. #define MAX_SC_VALUE            0x7f
  259.  
  260.  
  261. /*
  262.  * Text representing the major 'sense key' errors
  263.  */
  264. #define SENSE_KEY_INFO  {                               \
  265.     "No Sense Available",           /* 0x00 */          \
  266.     "Soft Error",                   /* 0x01 */          \
  267.     "Unit Not Ready",               /* 0x02 */          \
  268.     "Media Error",                  /* 0x03 */          \
  269.     "Hardware Error",               /* 0x04 */          \
  270.     "Illegal Request",              /* 0x05 */          \
  271.     "Unit Attention",               /* 0x06 */          \
  272.     "Write Protected",              /* 0x07 */          \
  273.     "Blank Check",                  /* 0x08 */          \
  274.     "Vendor Unique",                /* 0x09 */          \
  275.     "Copy Aborted",                 /* 0x0a */          \
  276.     "Aborted Command",              /* 0x0b */          \
  277.     "Equal Error",                  /* 0x0c */          \
  278.     "Volume Overflow",              /* 0x0d */          \
  279.     "Miscompare Error",             /* 0x0e */          \
  280.     0}                              /* 0x0f */
  281. #endif  /* SK_NO_SENSE */
  282.  
  283. /*
  284.  * Text representing the additional 'sense code' errors.
  285.  */
  286. #define SENSE_CODE_INFO {                               \
  287.     "No Additional Information",    /* 0x00 */          \
  288.     "No Index/Sector Signal",       /* 0x01 */          \
  289.     "No Seek Complete",             /* 0x02 */          \
  290.     "Write Fault",                  /* 0x03 */          \
  291.     "Drive Not Ready",              /* 0x04 */          \
  292.     "Drive Not Selected",           /* 0x05 */          \
  293.     "Track Zero Not Found",         /* 0x06 */          \
  294.     "Multiple Drives Selected",     /* 0x07 */          \
  295.     "Logical Unit Comms. Failure",  /* 0x08 */          \
  296.     "Tracking Error",               /* 0x09 */          \
  297.     0L, 0L, 0L, 0L, 0L, 0L,         /* 0x0a -> 0x0f */  \
  298.     "ID CRC or ECC Error",          /* 0x10 */          \
  299.     "Unrecoverable Read Error",     /* 0x11 */          \
  300.     "No Address Mark in ID Field",  /* 0x12 */          \
  301.     "No Address Mark in Data Field",/* 0x13 */          \
  302.     "Sector Not Found",             /* 0x14 */          \
  303.     "Seek Error",                   /* 0x15 */          \
  304.     "Data Sync Mark Error",         /* 0x16 */          \
  305.     "Recovered Data Error (Retry)", /* 0x17 */          \
  306.     "Recovered Data Error (ECC)",   /* 0x18 */          \
  307.     "Defect List Error",            /* 0x19 */          \
  308.     "Parameter Overrun",            /* 0x1a */          \
  309.     "Synchronous Transfer Error",   /* 0x1b */          \
  310.     "Primary Defect List Lost",     /* 0x1c */          \
  311.     "Compare Error",                /* 0x1d */          \
  312.     "Recovered ID Error (ECC)",     /* 0x1e */          \
  313.     0L,                             /* 0x1f */          \
  314.     "Invalid Command Code",         /* 0x20 */          \
  315.     "Illegal Block Address",        /* 0x21 */          \
  316.     "Illegal Function for Device",  /* 0x22 */          \
  317.     "Volume Overflow",              /* 0x23 */          \
  318.     "Illegal Field in CDB",         /* 0x24 */          \
  319.     "Invalid Logical Unit Number",  /* 0x25 */          \
  320.     "Invalid Field in Param. List", /* 0x26 */          \
  321.     "Media Write Protected",        /* 0x27 */          \
  322.     "Media Changed",                /* 0x28 */          \
  323.     "Device Reset Occurred",        /* 0x29 */          \
  324.     "Mode Select Params. Changed",  /* 0x2a */          \
  325.     0L, 0L, 0L, 0L, 0L,             /* 0x2b -> 0x2f */  \
  326.     "Incompatible Cartridge",       /* 0x30 */          \
  327.     "Media Format Corrupted",       /* 0x31 */          \
  328.     "Defect List Full",             /* 0x32 */          \
  329.     0L, 0L, 0L, 0L, 0L, 0L,         /* 0x33 -> 0x38 */  \
  330.     0L, 0L, 0L, 0L, 0L, 0L, 0L,     /* 0x39 -> 0x3f */  \
  331.     "RAM Failure",                  /* 0x40 */          \
  332.     "Data Path Diagnostic Failure", /* 0x41 */          \
  333.     "Power On Diagnostic Failure",  /* 0x42 */          \
  334.     "Message Reject Error",         /* 0x43 */          \
  335.     "Internal Controller Error",    /* 0x44 */          \
  336.     "Select/Reselect Failed",       /* 0x45 */          \
  337.     "Unsuccessful Soft Reset",      /* 0x46 */          \
  338.     "Scsi Interface Parity Error",  /* 0x47 */          \
  339.     "Initiator Detected Error",     /* 0x48 */          \
  340.     "Inappropriate/Illegal Message",/* 0x49 */          \
  341.     "Unable to Reselect",           /* 0x4a */          \
  342.     "No Target Recovery from Error",/* 0x4b */          \
  343.     0L, 0L, 0L, 0L,                 /* 0x4c -> 0x4f */  \
  344.     "Illegal Block Descriptor",     /* 0x50 */          \
  345.     "Illegal Use of Some Field (?)",/* 0x51 */          \
  346.     "Defect List Header Unsupp.",   /* 0x52 */          \
  347.     0L, 0L, 0L, 0L, 0L, 0L,         /* 0x53 -> 0x58 */  \
  348.     0L, 0L, 0L, 0L, 0L, 0L, 0L,     /* 0x59 -> 0x5f */  \
  349.     "Device Reset Occurred",        /* 0x60 */          \
  350.     "Mode Select Params. Changed",  /* 0x61 */          \
  351.     0L, 0L, 0L, 0L, 0L, 0L,         /* 0x62 -> 0x67 */  \
  352.     0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, /* 0x68 -> 0x6f */  \
  353.     0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, /* 0x70 -> 0x77 */  \
  354.     0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L} /* 0x78 -> 0x7f */  
  355.  
  356.  
  357. /*
  358.  * Forward / prototype declarations for Scsi driver in 'libscsi.a'
  359.  */
  360. extern short Scsi_Test_Unit_Ready(u_char);
  361. extern short Scsi_Rezero(u_char);
  362. #define Scsi_Rewind Scsi_Rezero
  363. extern short Scsi_Request_Sense(u_char, void *, u_short);
  364. extern short Scsi_RdWr_Rand(Sc_RW, u_char, void *, u_char, u_char, u_long);
  365. extern short Scsi_RdWr_Seq(Sc_RW, u_char, void *, u_char, u_char);
  366. extern short Scsi_Seek_Rand(u_char, u_long);
  367. extern short Scsi_Seek_Seq(u_char, u_long);
  368. extern short Scsi_File_Marks(u_char, u_char);
  369. extern short Scsi_Space(u_char, u_long, u_char);
  370. extern short Scsi_Inquire(u_char, void *, u_short);
  371. extern short Scsi_Erase(u_char);
  372. extern short Scsi_Mode_Sense(u_char, u_char, void *, u_short);
  373. extern short Scsi_Load_Unload(u_char, u_char);
  374. extern short Scsi_Prevent_Allow(u_char, u_char);
  375. extern char *Scsi_Set_Timeouts(u_char, char *, Sc_Timeout *);
  376.  
  377. #endif  /* __sys_scsi_h */
  378.